﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE.Product.MonthlyCharge
{
    public partial class ctrlMonthlyExpence : DevExpress.XtraEditors.XtraUserControl
    {
        ClsMonthlyExpenceDAO clsMonthlyExpenceDAO = new ClsMonthlyExpenceDAO();
        DataTable dt;
        MonthlyExpence b = new MonthlyExpence();

        public ctrlMonthlyExpence()
        {
            InitializeComponent();
        }

        void Reload(object sender, EventArgs e)
        {
            dt = clsMonthlyExpenceDAO.GetAllMonthlyExpence();
            gridControl1.DataSource = dt;
        }
        private void ctrlMonthlyExpence_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_MonthlyExpenceAdd frmAdd = new frm_MonthlyExpenceAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            frm_MonthlyExpenceEdit frmEdit = new frm_MonthlyExpenceEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ExpenceID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ExpenceID").ToString();
            frmEdit.YearMonth = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "YearMonth").ToString();
            frmEdit.Amount = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Amount").ToString();
            frmEdit.Show();
        }

        private void bntDelete_Click(object sender, EventArgs e)
        {
            b.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clsMonthlyExpenceDAO.DeleteMonthlyExpence(b);
            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            bntDelete_Click(sender, e);
        }
    }
}
